package com.avic.rong.goodsSort.adapter.drawerAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.goodsSort.bean.secondDrawerBean.GoodsSortWdDrwerBean;

import java.util.ArrayList;

/**
 * Created by Chenjiaxin on 2019/7/15 20:22
 * E-Mail Address：16601203965@163.com
 */
public class GoodsSortWdDrawerRvAdapter extends RecyclerView.Adapter<GoodsSortWdDrawerRvAdapter.GoodsSortWdDrawerRvViewHolder> {
    private Context context;
    private ArrayList<GoodsSortWdDrwerBean> wdDrwerList = new ArrayList<>();
    private LayoutInflater inflater;
    private View view;
    private GoodsSortWdDrawerListener goodsSortWdDrawerListener;

    public GoodsSortWdDrawerListener getGoodsSortWdDrawerListener() {
        return goodsSortWdDrawerListener;
    }

    public void setGoodsSortWdDrawerListener(GoodsSortWdDrawerListener goodsSortWdDrawerListener) {
        this.goodsSortWdDrawerListener = goodsSortWdDrawerListener;
    }

    public GoodsSortWdDrawerRvAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setWdDrwerList(ArrayList<GoodsSortWdDrwerBean> wdDrwerList) {
        this.wdDrwerList = wdDrwerList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public GoodsSortWdDrawerRvViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        view = inflater.inflate(R.layout.view_goods_rv_item1, viewGroup, false);
        return new GoodsSortWdDrawerRvViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsSortWdDrawerRvViewHolder holder, int i) {
        holder.tv.setText(wdDrwerList.get(i).getCatName());
        holder.tv.setSelected(wdDrwerList.get(i).isSelected());
        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goodsSortWdDrawerListener.setWdDrawerSelected(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return wdDrwerList.size();
    }

    class GoodsSortWdDrawerRvViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        public GoodsSortWdDrawerRvViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.goods_Item_tv1);
        }
    }
    public interface GoodsSortWdDrawerListener {
        void setWdDrawerSelected(int index);
    }
}
